package main_form

import (
	"encoding/xml"
	"fmt"
	"io/ioutil"
)

type SceneWidget struct {
	Name         string     `xml:"Name,attr"`
	SkinTempName string     `xml:"SkinTempName,attr"`
	Properties   []Property `xml:"Property"`
}

type Property struct {
	Key   string `xml:"Key,attr"`
	Value string `xml:"Value,attr"`
}

// SceneConfig 非主窗口
type SceneConfig struct {
	XMLName xml.Name      `xml:"root"`
	Widgets []SceneWidget `xml:"Widget"`
}

func LoadScene(filename string) (*MainSceneConfig, error) {
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, err
	}
	return loadSceneConfigFromData(data)
}

func loadSceneConfigFromData(data []byte) (*MainSceneConfig, error) {
	var config MainSceneConfig
	err := xml.Unmarshal([]byte(data), &config)
	if err != nil {
		fmt.Println("Error:", err)
		return nil, err
	}
	return &config, nil
}
